
const through = require('through2')
var gutil = require('gulp-util');
var PluginError = gutil.PluginError
const PLUGIN_NAME = 'gulp-prefixer'
var marked = require('marked')

var header = new Buffer('# this is header\n')

function test() {
  console.log('test')
  // throw new PluginError(PLUGIN_NAME, 'Missing prefix text!');
  function bufferContent (file, enc, cb) {
    // console.log('bufferContent')
    console.log(file.isBuffer(), file.isStream())
    if (file.isBuffer()) {
      // file.contents = Buffer.concat([header, file.contents])
      file.contents = new Buffer(marked(String(file.contents)))
      file.path = file.path.replace(/\.md/i, '.html')
    }

    // this.push(file)
    cb(null, file)
    // cb()
  }
  function endBuffer () {
    console.log('endBuffer')
  }
  return through.obj(bufferContent, endBuffer)
}

module.exports = test